﻿using System;
using System.Windows.Input;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.ServiceLocation;

using Acceron.Univeristy.Common;
using Acceron.Univerisy.Modules.Scheduling.Commands;

namespace Acceron.Univerisy.Modules.Scheduling.ViewModels
{
    public class ScheduleViewModel : ViewModelBase
    {
        bool pressed = false;

        public ScheduleViewModel()
        {
            this.Initialize();
        }

        /// <summary>
        /// Loads the view for dashboard.
        /// </summary>
        public ICommand SaveSchedule { get; set; }

        #region Events handler

        private void OnButtonClicked(string command)
        {
            pressed = true;
        }

        #endregion


        #region Private Methods
        /// <summary>
        /// Initializes the view model.
        /// </summary>
        private void Initialize()
        {
            // Initialize command properties
            this.SaveSchedule = new SaveScheduleCommand(this, (x) => { return !pressed; });
            

            // Subscribe to Composite Presentation Events
            var eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>();
            var clickedEvent = eventAggregator.GetEvent<ButtonClickedEvent>();

            clickedEvent.Subscribe(OnButtonClicked, ThreadOption.UIThread);
        }

        #endregion
    }
}
